import type { PageParams, PageResult } from '@/types/global'
import type {
  BannerItem,
  CategoryItem,
  GetHomeGoodsGuessLikeData,
  GetHomeGoodsGuessLikeResult,
  GuessItem,
  HotItem,
  NewItem,
  RecommendData,
  RecommendResult,
} from '@/types/home'
import { http } from '@/utils/http'

/**
 * 首页-广告区域
 * @param distributionSite 说明：广告区域展示位置（投放位置 投放位置，1为首页，2为分类商品页） 默认是1
 */
export function getHomeBanner(distributionSite = 1) {
  return http<BannerItem[]>({
    method: 'GET',
    url: '/home/banner',
    data: {
      distributionSite: distributionSite,
    },
  })
}

export function getHomeBannerAPI(distributionSite = 1) {
  return http<BannerItem[]>({
    method: 'GET',
    url: '/home/banner',
    data: {
      distributionSite: distributionSite,
    },
  })
}

/**
 * 首页-前台类目-小程序
 */
export function getHomeCategoryHeadMutli() {
  return http<CategoryItem[]>({
    method: 'GET',
    url: '/home/category/head/mutli',
  })
}

export function getHomeCategoryHeadMutliAPI() {
  return http<CategoryItem[]>({
    method: 'GET',
    url: '/home/category/head/mutli',
  })
}

/**
 * 首页-人气推荐-小程序和app
 */
export function getHomeHotMutli() {
  return http<HotItem[]>({
    method: 'GET',
    url: '/home/hot/mutli',
  })
}

export function getHomeHotAPI() {
  return http<HotItem[]>({
    method: 'GET',
    url: '/home/hot/mutli',
  })
}

/**
 * 首页-新鲜好物-pc-小程序
 * @param limit 说明：默认值为 4，指定响应数据中商品的数量
 */
export function getHomeNew(limit = 4) {
  return http<NewItem[]>({
    method: 'GET',
    url: '/home/new',
    data: {
      limit: limit,
    },
  })
}

export function getHomeNewAPI(limit = 4) {
  return http<NewItem[]>({
    method: 'GET',
    url: '/home/new',
    data: {
      limit: limit,
    },
  })
}

/**
 * 首页-猜你喜欢-小程序和app
 */
export function getHomeGoodsGuessLike(data: GetHomeGoodsGuessLikeData) {
  return http<GetHomeGoodsGuessLikeResult>({
    method: 'GET',
    url: '/home/goods/guessLike',
    data: data,
  })
}

/**
 * 1特惠推荐_小程序
 * @param data 推荐请求参数
 */
export function getHomePreferenceMutli(data: RecommendData) {
  return http<RecommendResult>({
    method: 'GET',
    url: '/home/preference/mutli',
    data: data,
  })
}

/**
 * 2爆款推荐_小程序
 * @param data 推荐请求参数
 */
export function getHomeInVogueMutli(data: RecommendData) {
  return http<RecommendResult>({
    method: 'GET',
    url: '/home/inVogue/mutli',
    data: data,
  })
}

/**
 * 通用推荐_小程序
 * @param url  什么格式的推荐
 * @param data 推荐请求参数
 */
export function getHomeRecommend(url: string, data: RecommendData) {
  return http<RecommendResult>({
    method: 'GET',
    url: url,
    data: data,
  })
}

/**
 * 猜你喜欢-小程序
 * @param data 通用分页参数
 */
export const getHomeGoodsGuessLikeAPI = (data?: PageParams) => {
  return http<PageResult<GuessItem>>({
    method: 'GET',
    url: '/home/goods/guessLike',
    data,
  })
}
